#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define str string
#define all(x) (x).begin(),(x).end()
#define ms(a,t) memset(a,t,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define db double
const int maxn = 4e5+10;
const int mod = 998244353;
const ll INF = 0x3f3f3f3f;
const db eps = 1e-7;
int n,m;
bool vis[maxn];
vector<int> G[maxn];
int cnt1,cnt2;
void dfs(int x) {
	cnt1++; vis[x] = true;
	for(int to : G[x]) {
		cnt2++;
		if(!vis[to]) dfs(to);
	}
}
void Solve() {
	cin >> n;
	for(int i = 1,u,v; i <= n; i++) {
		cin >> u >> v;
		G[u].pb(v); G[v].pb(u);
	}
	int ans = 0;
	for(int i = 1; i <= 2*n; i++) if(!vis[i]) {
		cnt1 = cnt2 = 0;
		dfs(i);
//		cerr<<cnt1<<' '<<cnt2<<'\n';
		ans += min(cnt1,cnt2/2);
	}
	cout<<ans<<'\n';
}
int main() {
	freopen("pairint.in","r",stdin);
	freopen("pairint.out","w",stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	int T; cin >> T; while(T--)
	Solve();
	return 0;
}
